!function ($, c, x, l) {
  var t = function (c, x) {
    this.$element = c;
    this.defaults = {
      type: 1,
      vOffset: 5,
      vSpace: 5,
      imgName: ["1.jpg", "2.jpg"],
      imgSize: {
        width: "400px",
        height: "200px"
      },
      blockSize: {
        width: "50px",
        height: "50px"
      },
      barSize: {
        width: "400px",
        height: "40px"
      },
      ready: function () {},
      success: function () {},
      error: function () {}
    };
    this.options = $.extend({}, this.defaults, x);
  };

  t.prototype = {
    init: function () {
      var m = this;
      this.loadDom();
      this.options.ready();
      this.$element.length > 0 && (this.$element[0].onselectstart = x.body.ondrag = function () {
        return !1;
      });
      this.htmlDoms.move_block.on("touchstart", function (c) {
        m.start(c);
      });
      this.htmlDoms.move_block.on("mousedown", function (c) {
        m.start(c);
      });
      c.addEventListener("touchmove", function (c) {
        m.move(c);
      });
      c.addEventListener("mousemove", function (c) {
        m.move(c);
      });
      c.addEventListener("touchend", function () {
        m.end();
      });
      c.addEventListener("mouseup", function () {
        m.end();
      });
      m.$element.find(".verify-refresh").on("click", function () {
        m.refresh();
      });
    },
    loadDom: function () {
      this.img_rand = Math.floor(Math.random() * this.options.imgName.length);
      var l = "",
          t = "";
      this.options.type != 1 && (l += "<div class=\"verify-img-panel\"><div  class=\"verify-refresh\"><i class=\"iconfont icon-refresh\"></i></div><div class=\"verify-gap\"></div></div>", t = "<div  class=\"verify-sub-block\"></div>");
      l += "<div class=\"verify-bar-area\"><span  class=\"verify-msg\">请按住滑块，拖动到最右边</span><div class=\"verify-left-bar\"><span  class=\"verify-msg\"></span><div  class=\"verify-move-block\"><i  class=\"verify-icon iconfont icon-right\"></i>" + t + "</div></div></div>";
      this.$element.append(l);
      this.htmlDoms = {
        gap: this.$element.find(".verify-gap"),
        sub_block: this.$element.find(".verify-sub-block"),
        img_panel: this.$element.find(".verify-img-panel"),
        bar_area: this.$element.find(".verify-bar-area"),
        move_block: this.$element.find(".verify-move-block"),
        left_bar: this.$element.find(".verify-left-bar"),
        msg: this.$element.find(".verify-msg"),
        icon: this.$element.find(".verify-icon"),
        refresh: this.$element.find(".verify-refresh")
      };
      this.status = !1;
      this.setSize = this.resetSize(this);
      this.htmlDoms.gap.css({
        width: this.options.blockSize.width,
        height: this.options.blockSize.height
      });
      this.htmlDoms.sub_block.css({
        width: this.options.blockSize.width,
        height: this.options.blockSize.height
      });
      this.htmlDoms.img_panel.css({
        width: this.setSize.img_width,
        height: this.setSize.img_height,
        background: "url(images/" + this.options.imgName[this.img_rand] + ")",
        "background-size": this.setSize.img_width + " " + this.setSize.img_height
      });
      this.htmlDoms.bar_area.css({
        width: this.setSize.bar_width,
        height: this.options.barSize.height,
        "line-height": this.options.barSize.height
      });
      this.htmlDoms.move_block.css({
        width: this.options.barSize.height,
        height: this.options.barSize.height
      });
      this.htmlDoms.left_bar.css({
        width: this.options.barSize.height,
        height: this.options.barSize.height
      });
      this.randSet();
    },
    start: function (c) {
      this.htmlDoms.msg.text("");
      this.htmlDoms.move_block.css("background-color", "#7AC23C");
      this.htmlDoms.left_bar.css("border-color", "#7AC23C");
      this.htmlDoms.icon.css("color", "#fff");
      c.stopPropagation();
      this.status = !0;
    },
    move: function (c) {
      if (this.status) {
        if (c.touches) s = c.touches[0].pageX;else var s = c.clientX;
        var i = s - t.prototype.getLeft(this.htmlDoms.bar_area[0]);
        this.options.type != 1 ? i >= this.htmlDoms.bar_area[0].offsetWidth - parseInt(parseInt(this.options.blockSize.width) / 2) - 2 && (i = this.htmlDoms.bar_area[0].offsetWidth - parseInt(parseInt(this.options.blockSize.width) / 2) - 2) : i >= this.htmlDoms.bar_area[0].offsetWidth - parseInt(parseInt(this.options.barSize.height) / 2) + 3 ? (this.$element.find(".verify-msg:eq(1)").text("松开验证"), i = this.htmlDoms.bar_area[0].offsetWidth - parseInt(parseInt(this.options.barSize.height) / 2) + 3) : this.$element.find(".verify-msg:eq(1)").text("");
        i <= 0 && (i = parseInt(parseInt(this.options.blockSize.width) / 2));
        var e = i - parseInt(parseInt(this.options.blockSize.width) / 2);
        e < 0 && (e = 0);
        this.htmlDoms.move_block.css("left", e + "px");
        this.htmlDoms.left_bar.css("width", e + "px");
      }
    },
    end: function () {
      var l = this;

      if (this.status) {
        if (this.options.type != 1) {
          var a = parseInt(this.options.vOffset);
          parseInt(this.htmlDoms.gap.css("left")) >= parseInt(this.htmlDoms.move_block.css("left")) - a && parseInt(this.htmlDoms.gap.css("left")) <= parseInt(this.htmlDoms.move_block.css("left")) + a ? (this.htmlDoms.move_block.css("background-color", "#5cb85c"), this.htmlDoms.left_bar.css({
            "border-color": "#5cb85c",
            "background-color": "#fff"
          }), this.htmlDoms.icon.css("color", "#fff"), this.htmlDoms.icon.removeClass("icon-right"), this.htmlDoms.icon.addClass("icon-check"), this.htmlDoms.refresh.hide(), this.htmlDoms.move_block.unbind("mousedown touchstart"), this.options.success()) : (this.htmlDoms.move_block.css("background-color", "#d9534f"), this.htmlDoms.left_bar.css("border-color", "#d9534f"), this.htmlDoms.icon.css("color", "#fff"), this.htmlDoms.icon.removeClass("icon-right"), this.htmlDoms.icon.addClass("icon-close"), setTimeout(function () {
            l.htmlDoms.move_block.animate({
              left: "0px"
            }, "fast");
            l.htmlDoms.left_bar.animate({
              width: "40px"
            }, "fast");
            l.htmlDoms.left_bar.css({
              "border-color": "#ddd"
            });
            l.htmlDoms.move_block.css("background-color", "#fff");
            l.htmlDoms.icon.css("color", "#000");
            l.htmlDoms.icon.removeClass("icon-close");
            l.htmlDoms.icon.addClass("icon-right");
            l.$element.find(".verify-msg:eq(0)").text("请按住滑块，拖动到最右边");
          }, 400), this.options.error());
        } else parseInt(this.htmlDoms.move_block.css("left")) >= parseInt(this.setSize.bar_width) - parseInt(this.options.barSize.height) - parseInt(this.options.vOffset) ? (this.htmlDoms.move_block.css("background-color", "white"), this.htmlDoms.left_bar.css({
          color: "#4cae4c",
          "border-color": "#5cb85c",
          "background-color": "#fff"
        }), this.htmlDoms.icon.css("color", "#fff"), this.htmlDoms.icon.removeClass("icon-right"), this.htmlDoms.icon.addClass("icon-check"), this.htmlDoms.refresh.hide(), this.htmlDoms.left_bar.css({
          "background-color": "#7AC23C",
          color: "white"
        }), this.htmlDoms.move_block.unbind("mousedown"), this.htmlDoms.move_block.unbind("touchstart"), this.options.success()) : (this.htmlDoms.move_block.css("background-color", "#d9534f"), this.htmlDoms.left_bar.css("border-color", "#d9534f"), this.htmlDoms.icon.css("color", "#fff"), this.htmlDoms.icon.removeClass("icon-right"), this.htmlDoms.icon.addClass("icon-close"), setTimeout(function () {
          l.htmlDoms.move_block.animate({
            left: "0px"
          }, "fast");
          l.htmlDoms.left_bar.animate({
            width: "40px"
          }, "fast");
          l.htmlDoms.left_bar.css({
            "border-color": "#ddd"
          });
          l.htmlDoms.move_block.css("background-color", "#fff");
          l.htmlDoms.icon.css("color", "#000");
          l.htmlDoms.icon.removeClass("icon-close");
          l.htmlDoms.icon.addClass("icon-right");
          l.$element.find(".verify-msg:eq(0)").text("请按住滑块，拖动到最右边");
        }, 400), this.options.error());

        this.status = !1;
      }
    },
    resetSize: function (x) {
      var l,
          t,
          a,
          s,
          n = x.$element.parent().width() || $(c).width(),
          m = x.$element.parent().height() || $(c).height();
      l = x.options.imgSize.width.indexOf("%") != -1 ? parseInt(x.options.imgSize.width) / 100 * n + "px" : x.options.imgSize.width;
      t = x.options.imgSize.height.indexOf("%") != -1 ? parseInt(x.options.imgSize.height) / 100 * m + "px" : x.options.imgSize.height;
      a = x.options.barSize.width.indexOf("%") != -1 ? parseInt(x.options.barSize.width) / 100 * n + "px" : x.options.barSize.width;
      s = x.options.barSize.height.indexOf("%") != -1 ? parseInt(x.options.barSize.height) / 100 * m + "px" : x.options.barSize.height;
      return {
        img_width: l,
        img_height: t,
        bar_width: a,
        bar_height: s
      };
    },
    randSet: function () {
      var a = Math.floor(Math.random() * 9 + 1),
          s = Math.floor(Math.random() * 9 + 1),
          i = a * parseInt(this.setSize.img_height) / 15 + parseInt(this.setSize.img_height) * 0.1,
          e = s * parseInt(this.setSize.img_width) / 15 + parseInt(this.setSize.img_width) * 0.1;
      this.$element.find(".verify-img-panel").css("margin-bottom", this.options.vSpace + "px");
      this.$element.find(".verify-gap").css({
        top: i,
        left: e
      });
      this.$element.find(".verify-sub-block").css({
        top: "-" + (parseInt(this.setSize.img_height) - i + this.options.vSpace + 2) + "px",
        "background-image": "url(images/" + this.options.imgName[this.img_rand] + ")",
        "background-size": this.setSize.img_width + " " + this.setSize.img_height,
        "background-position-y": "-" + i + "px",
        "background-position-x": "-" + e + "px"
      });
    },
    refresh: function () {
      this.randSet();
      this.img_rand = Math.floor(Math.random() * this.options.imgName.length);
      this.$element.find(".verify-sub-block").css({
        "background-image": "url(images/" + this.options.imgName[this.img_rand] + ")",
        "background-size": this.setSize.img_width + " " + this.setSize.img_height
      });
      this.$element.find(".verify-img-panel").css({
        background: "url(images/" + this.options.imgName[this.img_rand] + ")",
        "background-size": this.setSize.img_width + " " + this.setSize.img_height
      });
    },
    getLeft: function (c) {
      var t = $(c).offset().left;
      return t;
    }
  };

  $.fn.slideVerify = function (c, x) {
    var s = new t(this, c);
    s.init();
  };
}(jQuery, window, document);